package com.ftwj.demo.permission.controller;

import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ftwj.demo.config.swagger.DataType;
import com.ftwj.demo.config.swagger.ParamType;
import com.ftwj.demo.permission.entity.OperateBean;
import com.ftwj.demo.permission.service.OperateService;
import com.ftwj.demo.utils.result.MessageEnum;
import com.ftwj.demo.utils.result.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
*
* <p>Title: OperateController</p>  
* <p>Description: 日志管理前端控制器</p>
* <p>Copyright: Copyright (c) 2020 </p>  
* <p>Company: 兰州飞天网景信息产业有限公司</p>    
* @author WangSLi
* @date 2020年4月4日 下午5:57:16
* @version V1.0
*/
@RestController
@RequestMapping("/operate")
@Api(tags="日志管理接口", value="日志管理")
@Validated
public class OperateController {
	
	@Autowired
	private OperateService service;
	
	/**
	 * <p>Title: page</p>  
	 * <p>Description: 分页查询日志</p>  
	 * @param current
	 * @param size
	 * @param moduleName
	 * @param userId
	 * @param time1
	 * @param time2
	 * @author HeYang
	 * @date 2020年4月23日  
	 * @version 1.0
	 */
	@GetMapping("/page")
	@ApiOperation(value="分页列表条件查询（DONE）", notes="备注",code=0, httpMethod="GET")
    @ApiImplicitParams({
    	@ApiImplicitParam(name="current", value="当前页数", dataType=DataType.INTEGER, paramType=ParamType.QUERY, defaultValue="1")
    	,@ApiImplicitParam(name="size", value="每页显示条数", dataType=DataType.INTEGER, paramType=ParamType.QUERY, defaultValue="10")
    })
	public ResultBean<?> page(@RequestParam(required = true) Integer current, @RequestParam(required = true) Integer size
			,@RequestParam(name="moduleName",required=false) String moduleName
			,@RequestParam(name="userName",required=false) String userName
			,@RequestParam(name="time1",required=false) String time1
			,@RequestParam(name="time2",required=false)  String time2
			) {
		IPage<OperateBean> page=new Page<OperateBean>(current, size);
		IPage<Map<String, Object>> data = service.pageMaps(page,time1,time2,moduleName,userName);
		return ResultBean.success(data);
	}
	
	/**
	 * <p>Title: delete</p>  
	 * <p>Description: 日志批量删除</p>  
	 * @param ids
	 * @author HeYang
	 * @date 2020年4月23日  
	 * @version 1.0
	 */
	@DeleteMapping("/dels")
	@ApiOperation(value="批量物理删除", notes="备注",code=0,httpMethod="DELETE")
	public ResultBean<?> delete(@RequestBody List<Integer> ids) {
		if(service.removeByIds(ids)) {
			return ResultBean.success();
		} else {
			return ResultBean.error(MessageEnum.SERVER_FAILED);
		}
	}
	
	/**
	 * <p>Title: deleteByDate</p>  
	 * <p>Description: 按照时间段物理删除</p>  
	 * @param time1
	 * @param time2
	 * @author HeYang
	 * @date 2020年4月23日  
	 * @version 1.0
	 */
	@DeleteMapping("/deleteByDate")
	@ApiOperation(value="批量物理删除(根据时间段)", notes="备注",code=0,httpMethod="DELETE")
	public ResultBean<?> deleteByDate(@RequestParam(name = "time1",required = false) String time1
										,@RequestParam(name = "time2",required = false) String time2) {
		if(service.deleteByDate(time1,time2) != null) {
			return ResultBean.success();
		} else {
			return ResultBean.error(MessageEnum.SERVER_FAILED);
		}
	}
}
